package com.hdu.dwh.service.impl.model_impl;

import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
// import com.hdu.dwh.dtos.model_dtos.ConnectionColumn;
import com.hdu.dwh.enums.JoinType;
import com.hdu.dwh.mapper.model_mapper.ConnectionColumnMapper;
import com.hdu.dwh.pojos.model_pojos.ConnectionColumn;
import com.hdu.dwh.pojos.model_pojos.MetaColumn;
import com.hdu.dwh.service.model_service.ConnectionColumnService;
import com.hdu.dwh.service.model_service.MetaColumnService;

@Service
public class ConnectionColumnServiceImpl extends ServiceImpl<ConnectionColumnMapper, ConnectionColumn>
        implements ConnectionColumnService {
    @Autowired
    MetaColumnService metaColumnService;

    @Override
    public void createConnectionColumns(Set<ConnectionColumn> connectionColumns, Long modelId) {
        for (ConnectionColumn connectionColumn : connectionColumns) {
            createConnectionColumn(
                    connectionColumn.getLeftDatabaseName(),
                    connectionColumn.getLeftTableName(),
                    connectionColumn.getLeftColumnName(),
                    connectionColumn.getRightDatabaseName(),
                    connectionColumn.getRightTableName(),
                    connectionColumn.getRightColumnName(),
                    connectionColumn.getJoinType(), modelId);

        }
    }

    private ConnectionColumn createConnectionColumn(
            String l_db, String l_tb, String l_col, String r_db, String r_tb, String r_col, JoinType joinType, Long modelId) {
        ConnectionColumn col = new ConnectionColumn(l_db, l_tb, l_col, r_db, r_tb, r_col, joinType, modelId);
        this.save(col);
        return col;
    }

    @Deprecated
    private MetaColumn queryCol(String tableName, String Column, Long modelId) {
        MetaColumn s_metaColumn = metaColumnService.findByTableNameAndColumnNameAndModelId(tableName, Column, modelId);
        return s_metaColumn;
    }

}
